import Vue from 'vue'
import 'normalize.css/normalize.css' // A modern alternative to CSS resets
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import locale from 'element-ui/lib/locale/lang/en' // lang i18n
import "./assets/css/index.css";
import "./assets/css/iconfont/iconfont.css";
import App from './App'
import router from './router'
import store from './store'
import config from "./assets/js/config";
import NProgress from "nprogress"
import "nprogress/nprogress.css"
// markdown组件
import mavonEditor from 'mavon-editor'
import 'mavon-editor/dist/css/index.css'
// echarts相关
import ECharts from "vue-echarts"
import "echarts/lib/chart/line"
import "echarts/lib/chart/pie"
import "echarts/lib/chart/bar"
import "echarts/lib/chart/map"
import "echarts/lib/component/tooltip"
import "echarts/lib/component/legend"
import "echarts/lib/component/title"
import dayjs from "dayjs"
import tagCloud from "./components/tag-cloud"
import VueCalendarHeatmap from "vue-calendar-heatmap"

Vue.prototype.config = config;
Vue.use(tagCloud)
Vue.use(VueCalendarHeatmap);
Vue.use(dayjs)
Vue.use(mavonEditor)
Vue.use(ElementUI, { locale })
Vue.component("v-chart", ECharts)
Vue.config.productionTip = false
Vue.prototype.$moment = dayjs

Vue.filter("date", function(value, formatStr = "YYYY-MM-DD") {
  return dayjs(value).format(formatStr)
});

Vue.filter("dateTime", function(value, formatStr = "YYYY-MM-DD HH:mm:ss") {
  return dayjs(value).format(formatStr)
})

NProgress.configure({
  easing: "ease", // 动画方式
  speed: 500, // 递增进度条的速度
  showSpinner: false, // 是否显示加载ico
  trickleSpeed: 200, // 自动递增间隔
  minimum: 0.3 // 初始化时的最小百分比
});

router.beforeEach((to, from, next) => {
  NProgress.start();
  if (to.path == "/login") {
    next();
  } else if (!store.state.userId) {
    next({ path: "/login" });
  } else {
    next();
  }
});


new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
